<?php

namespace app\modules\Order\models;

use Yii;

/**
 * This is the model class for table "order_contact".
 *
 * @property integer $id
 * @property integer $order_id
 * @property integer $customer_id
 * @property string $name
 * @property integer $gender
 * @property string $phone
 * @property string $mail
 * @property string $remark
 * @property integer $status
 * @property integer $user_id
 * @property string $created_at
 * @property string $updated_at
 */
class OrderContact extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'order_contact';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            //[['order_id'], 'required'],
            //[['order_id', 'customer_id', 'gender', 'status', 'user_id'], 'integer'],
            [['gender', 'status', 'user_id'], 'integer'],
            [['created_at', 'updated_at'], 'safe'],
            [['name', 'mail', 'remark'], 'string', 'max' => 255],
            [['phone'], 'string', 'max' => 64],
            [['company'], 'string', 'max' => 64],
        ];
    }

    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }
        return parent::beforeSave($insert);
    }//}}}



    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app.order', 'ID'),
            'order_id' => Yii::t('app.order', 'Order ID'),
            'customer_id' => Yii::t('app.order', 'Customer ID'),
            'name' => Yii::t('app.order', 'Name'),
            'gender' => Yii::t('app.order', 'Gender'),
            'phone' => Yii::t('app.order', 'Phone'),
            'mail' => Yii::t('app.order', 'Mail'),
            'remark' => Yii::t('app.order', 'Remark'),
            'status' => Yii::t('app.order', 'Status'),
            'user_id' => Yii::t('app.order', 'User ID'),
            'created_at' => Yii::t('app.order', 'Created At'),
            'updated_at' => Yii::t('app.order', 'Updated At'),
        ];
    }
}
